package com.xxq.gulimall.ware.service.impl;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxq.common.utils.PageUtils;
import com.xxq.common.utils.Query;

import com.xxq.gulimall.ware.dao.PurchaseDetailDao;
import com.xxq.gulimall.ware.entity.PurchaseDetailEntity;
import com.xxq.gulimall.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> queryWrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        Long status = (Long) params.get("status");
        Long wareId = (Long) params.get("wareId");
        if (key != null && !key.isEmpty()) {
            queryWrapper.like("sku_id", key);
        }
        if (status != null && wareId != null && wareId != 0) {
            HashMap<String, Long> map = new HashMap<>();
            map.put("status", status);
            map.put("ware_id", wareId);
            queryWrapper.allEq(map);
        }

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}